package com.association.controller;

import com.association.constant.CodeEnum;
import com.association.model.ResultResp;
import com.association.model.vo.UserVo;
import com.association.service.LoginService;
import com.association.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author 18244
 */
@RestController
public class LoginController {

    @Autowired
    public LoginService loginService;

    @PostMapping("/login")
    public ResultResp login(HttpServletRequest request, HttpServletResponse response, HttpSession session, @RequestBody UserVo userVo) {
        Map<String,Object> map = loginService.login(request, response, session, userVo);
        if(map.size()>0){
            return new ResultResp(map);
        }
        return new ResultResp(CodeEnum.LOGIN_ERROR);
    }
}
